


const BASE_URL = "http://127.0.0.1:996/api"
export function request<T = any>({ url, loading = true, loadingText = '加载中', ...options }: UniApp.RequestOptions & { loading?: boolean, loadingText?: string }){
	loading ? uni.showLoading({
	    title: loadingText
	  }) : '';
	  const token = uni.getStorageSync("Authorization");
	  const header =token? {'content-type': 'application/json',
	  'Authorization':token}:{'content-type': 'application/json'}
	  return new Promise<T>((resolve,reject)=>{
		  uni.request({
		  	 url: `${BASE_URL}${url}`,
		  	      header,
				  success: (res) => {
				  	loading ? uni.hideLoading() : '';
					const {data} = res
					if(data.code!==0){
						uni.showToast({
							title:data.message,
							duration:2000,
							icon:"none"
						})
						 reject(data.message);
					}else{
						resolve(data.result.records??data)
					}
					
				  },
				  ...options
		  })
	  })
}